package com.hqch.mina;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;

import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

public class MinaTimeServer {

	public static void main(String[] args) {
		IoAcceptor acceptor = new NioSocketAcceptor();
		acceptor.getFilterChain().addLast("Logger", new MinaLoggerFilter());
		acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(
				new TextLineCodecFactory(Charset.forName("UTF-8"))));
		
		acceptor.setHandler(new TimeServerHandler());
		acceptor.setDefaultLocalAddress(new InetSocketAddress(8080));
		try {
			acceptor.bind();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
